import 'dart:convert';
import 'dart:typed_data';

import 'package:flutter_admin/utils/utils.dart';

class ProductElectroncheckrecord {
  String? id;
  String? factoryId;
  String? workshopId;
  String? stationId;
  String? questiontypeId;
  String? uploadimg;
  String? checkdate;
  String? checkdateStart;
  String? checkdateEnd;
  String? causeanalysis;
  String? rectificationmeasures;
  String? questiondescription;
  String? effectiveverification;
  String? status;
  String? handleuserId;
  String? handledatetime;
  String? createUid;
  String? createDate;
  String? createDateStart;
  String? createDateEnd;
  String? writeUid;
  String? writeDate;
  String? factoryName;
  String? workshopName;
  String? stationName;
  String? questiontypeName;
  String? createName;
  // Uint8List? imageBytes;

  ProductElectroncheckrecord({
    this.id,
    this.factoryId,
    this.workshopId,
    this.stationId,
    this.questiontypeId,
    this.uploadimg,
    this.checkdate,
    this.checkdateStart,
    this.checkdateEnd,
    this.causeanalysis,
    this.rectificationmeasures,
    this.questiondescription,
    this.effectiveverification,
    this.status,
    this.handleuserId,
    this.handledatetime,
    this.createUid,
    this.createDate,
    this.createDateStart,
    this.createDateEnd,
    this.writeUid,
    this.writeDate,
    this.factoryName,
    this.questiontypeName,
    this.stationName,
    this.workshopName,
    this.createName,
    //this.imageBytes,
  });

  ProductElectroncheckrecord copyWith({
    String? id,
    String? factoryId,
    String? workshopId,
    String? stationId,
    String? questiontypeId,
    String? uploadimg,
    String? checkdate,
    String? causeanalysis,
    String? rectificationmeasures,
    String? questiondescription,
    String? effectiveverification,
    String? status,
    String? handleuserId,
    String? handledatetime,
    String? createUid,
    String? createDate,
    String? writeUid,
    String? writeDate,
  }) {
    return new ProductElectroncheckrecord(
      id: id ?? this.id,
      factoryId: factoryId ?? this.factoryId,
      workshopId: workshopId ?? this.workshopId,
      stationId: stationId ?? this.stationId,
      questiontypeId: questiontypeId ?? this.questiontypeId,
      //uploadimg: uploadimg ?? this.uploadimg,
      checkdate: checkdate ?? this.checkdate,
      causeanalysis: causeanalysis ?? this.causeanalysis,
      rectificationmeasures:
          rectificationmeasures ?? this.rectificationmeasures,
      questiondescription: questiondescription ?? this.questiondescription,
      effectiveverification:
          effectiveverification ?? this.effectiveverification,
      status: status ?? this.status,
      handleuserId: handleuserId ?? this.handleuserId,
      handledatetime: handledatetime ?? this.handledatetime,
      createUid: createUid ?? this.createUid,
      createDate: createDate ?? this.createDate,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
    );
  }

  @override
  String toString() {
    return '''ProductElectroncheckrecord{
      id: id,
      factoryId: factoryId,
      workshopId: workshopId,
      stationId: stationId,
      questiontypeId: questiontypeId,
      uploadimg: uploadimg,
      checkdate: checkdate,
      causeanalysis: causeanalysis,
      rectificationmeasures: rectificationmeasures,
      questiondescription: questiondescription,
      effectiveverification: effectiveverification,
      status: status,
      handleuserId: handleuserId,
      handledatetime: handledatetime,
      createUid: createUid,
      createDate: createDate,
      writeUid: writeUid,
      writeDate: writeDate,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is ProductElectroncheckrecord &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          factoryId == other.factoryId &&
          workshopId == other.workshopId &&
          stationId == other.stationId &&
          questiontypeId == other.questiontypeId &&
          uploadimg == other.uploadimg &&
          checkdate == other.checkdate &&
          causeanalysis == other.causeanalysis &&
          rectificationmeasures == other.rectificationmeasures &&
          questiondescription == other.questiondescription &&
          effectiveverification == other.effectiveverification &&
          status == other.status &&
          handleuserId == other.handleuserId &&
          handledatetime == other.handledatetime &&
          createUid == other.createUid &&
          createDate == other.createDate &&
          writeUid == other.writeUid &&
          writeDate == other.writeDate);

  factory ProductElectroncheckrecord.fromMap(Map<String, dynamic> map) {
    return new ProductElectroncheckrecord(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      factoryName: map['factory_id'][1].toString() as String?,
      factoryId: map['factory_id'][0].toString() as String?,
      workshopName: map['workshop_id'][1].toString() as String?,
      workshopId: map['workshop_id'][0].toString() as String?,
      stationName: map['station_id'][1].toString() as String?,
      stationId: map['station_id'][0].toString() as String?,
      questiontypeName: map['questiontype_id'][1].toString() as String?,
      questiontypeId: map['questiontype_id'][0].toString() as String?,
      uploadimg: map['uploadimg'] != false ? map['uploadimg'] : null,
      checkdate: map['checkdate'] != false
          ? map['checkdate'].toString() as String?
          : "",
      causeanalysis: map['causeanalysis'] != false
          ? map['causeanalysis'].toString() as String?
          : "",
      rectificationmeasures: map['rectificationmeasures'] != false
          ? map['rectificationmeasures'].toString() as String?
          : "",
      questiondescription: map['questiondescription'] != false
          ? map['questiondescription'].toString() as String?
          : "",
      effectiveverification: map['effectiveverification'] != false
          ? map['effectiveverification'].toString() as String?
          : "",
      status: map['status'] != false ? map['status'].toString() as String? : "",
      handleuserId: map['handleuser_id'] != false
          ? map['handleuser_id'][1].toString() as String?
          : "",
      handledatetime: map['handledatetime'] != false
          ? map['handledatetime'].toString() as String?
          : "",
      createUid: map['create_uid'].toString() as String?,
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      writeUid: map['write_uid'] != false
          ? map['write_uid'].toString() as String?
          : "",
      writeDate: map['write_date'] != false
          ? map['write_date'].toString() as String?
          : "",
      createName: map['create_uid'][1].toString() as String?,
      // imageBytes:
      //     map['uploadimg'] != false ? Utils.encode(map['uploadimg']) : null,
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'factoryId': this.factoryId,
      'workshopId': this.workshopId,
      'stationId': this.stationId,
      'questiontypeId': this.questiontypeId,
      'uploadimg': this.uploadimg,
      'checkdate': this.checkdate,
      'causeanalysis': this.causeanalysis,
      'rectificationmeasures': this.rectificationmeasures,
      'questiondescription': this.questiondescription,
      'effectiveverification': this.effectiveverification,
      'status': this.status,
      'handleuser_id': this.handleuserId,
      'handledatetime': this.handledatetime,
      'createUid': this.createUid,
      'createDate': this.createDate,
      'writeUid': this.writeUid,
      'writeDate': this.writeDate,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.factoryId != null && this.factoryId != '')
        ['factory_id', '=', int.parse(this.factoryId!)],
      if (this.workshopId != null && this.workshopId != '')
        ['workshop_id', '=', int.parse(this.workshopId!)],
      if (this.stationId != null && this.stationId != '')
        ['station_id', '=', int.parse(this.stationId!)],
      if (this.status != null && this.status != '')
        ['status', '=', this.status],
      if (this.checkdateStart != null && this.checkdateStart != '')
        ['checkdate', '>=', this.checkdateStart! + " 00:00:00"],
      if (this.checkdateEnd != null && this.checkdateEnd != '')
        ['checkdate', '<=', this.checkdateEnd! + " 23:59:59"],
    ] as List;
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'factory_id': int.parse(this.factoryId!),
      'workshop_id': int.parse(this.workshopId!),
      'station_id': int.parse(this.stationId!),
      'questiontype_id': int.parse(this.questiontypeId!),
      'uploadimg': this.uploadimg,
      'checkdate': this.checkdate,
      'causeanalysis': this.causeanalysis,
      'rectificationmeasures': this.rectificationmeasures,
      'questiondescription': this.questiondescription,
      'effectiveverification': this.effectiveverification,
      'status': this.status,
      if (this.handleuserId != null && this.handleuserId != '')
        'handleuser_id': int.parse(this.handleuserId!),
      'handledatetime': this.handledatetime,
      'create_uid': this.createUid,
      'create_date': this.createDate,
      'write_uid': this.writeUid,
      'write_date': this.writeDate,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
